﻿
// LeftView.cpp : CLeftView 类的实现
//

#include "stdafx.h"
#include "Aries.h"

#include "AriesDoc.h"
#include "LeftView.h"
#include "RightView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CLeftView

IMPLEMENT_DYNCREATE(CLeftView, CTreeView)

BEGIN_MESSAGE_MAP(CLeftView, CTreeView)
	ON_WM_CREATE()
	ON_NOTIFY_REFLECT(TVN_SELCHANGED, &CLeftView::OnTvnSelchanged)
END_MESSAGE_MAP()


// CLeftView 构造/析构

CLeftView::CLeftView()
{
	// TODO: 在此处添加构造代码
}

CLeftView::~CLeftView()
{
}

BOOL CLeftView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或样式

	return CTreeView::PreCreateWindow(cs);
}

void CLeftView::OnInitialUpdate()
{
	CTreeView::OnInitialUpdate();

	// TODO: 调用 GetTreeCtrl() 直接访问 TreeView 的树控件，
	//  从而可以用项填充 TreeView。
}


// CLeftView 诊断

#ifdef _DEBUG
void CLeftView::AssertValid() const
{
	CTreeView::AssertValid();
}

void CLeftView::Dump(CDumpContext& dc) const
{
	CTreeView::Dump(dc);
}

CAriesDoc* CLeftView::GetDocument() // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAriesDoc)));
	return (CAriesDoc*)m_pDocument;
}
#endif //_DEBUG


// CLeftView 消息处理程序


int CLeftView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CTreeView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  在此添加您专用的创建代码
	GetDocument()->pLeftView = this;

	return 0;
}


void CLeftView::CreateFinanceStatement(void)
{
	// If there is anything in the tree, remove it
	GetTreeCtrl().DeleteAllItems();	
	CTreeCtrl &ctlFinanceStatement = this->GetTreeCtrl();	
	GetTreeCtrl().ModifyStyle(NULL, TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT);
	
	HTREEITEM hRoot;
	HTREEITEM htype;
	hRoot = ctlFinanceStatement.InsertItem(_T("财务报表"));
	htype = ctlFinanceStatement.InsertItem(_T("资产负债表"), hRoot);
	htype = ctlFinanceStatement.InsertItem(_T("利润表"), hRoot);
	htype = ctlFinanceStatement.InsertItem(_T("现金流量表"), hRoot);

	hRoot = ctlFinanceStatement.InsertItem(_T("财务指标"));
	htype = ctlFinanceStatement.InsertItem(_T("自由现金流"), hRoot);
	htype = ctlFinanceStatement.InsertItem(_T("净利润增长率"), hRoot);
	htype = ctlFinanceStatement.InsertItem(_T("营收增长率"), hRoot);
	/*ctlFinanceStatement.InsertItem(_T("2004-2005"),htype);
	ctlFinanceStatement.InsertItem(_T("2003-2004"),htype);
	ctlFinanceStatement.InsertItem(_T("2002-2001"),htype);
	ctlFinanceStatement.InsertItem(_T("2000-2001"),htype);
	ctlFinanceStatement.InsertItem(_T("1999-2000"),htype);*/

    //ctlFinanceStatement.Expand(hRoot, TVE_EXPAND);

}


void CLeftView::OnTvnSelchanged(NMHDR *pNMHDR, LRESULT *pResult)
{
	
	// TODO: 在此添加控件通知处理程序代码

	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
	
	//CAriesDoc *pDoc = GetDocument();	// Get a reference to the tree control
	CTreeCtrl &ctlFinanceStatement = this->GetTreeCtrl();
	// Find out what item is selected in the tree
	HTREEITEM nodSelected = ctlFinanceStatement.GetSelectedItem();	
	// Get the string of the selected node
	CString strSelected = ctlFinanceStatement.GetItemText(nodSelected);

	// Just in case the selected node as a parent, get that parent
	HTREEITEM nodParent = ctlFinanceStatement.GetParentItem(nodSelected);
	// Find the string of the parent of the selected node, if it has a parent
	CString strParent   = ctlFinanceStatement.GetItemText(nodParent);
	SelectDisplayType(strSelected);
	

	//判断是否已经连接上数据库
	//if(theApp.m_pConn!=NULL)
	//{	
	//	// Now you can react depending on the selected node
	//	if( strSelected == _T("财务报表" ))
	//	{
	//		pDoc->pRightView->DisplayField(); 
	//	}
	//	//pDoc->pRightView->DisplayField(); 
	//	if( strSelected == _T("资产负债表" ))
	//	{
	//		pDoc->pRightView->DisplayContent(1); 
	//	}

	//	if( strSelected == _T("利润表" ))
	//	{
	//		pDoc->pRightView->DisplayContent(2); 
	//	}

	//	if( strSelected == _T("现金流量表" ))
	//	{
	//		pDoc->pRightView->DisplayContent(3); 
	//	}
	//	if( strSelected == _T("自由现金流" ))
	//	{
	//		pDoc->pRightView->DisplayFinancialAnalysis(1); 
	//	}

	//}
	
}


// 根据选中节点名来显示相应内容
void CLeftView::SelectDisplayType(CString nodeSelected)
{
	
	CAriesDoc *pDoc = GetDocument();	// Get a reference to the tree control
	//判断是否已经连接上数据库
	if(theApp.m_pConn!=NULL)
	{	
		// Now you can react depending on the selected node
		if( nodeSelected == _T("财务报表" ))
		{
			pDoc->pRightView->DisplayField(); 
		}
		//pDoc->pRightView->DisplayField(); 
		if( nodeSelected == _T("资产负债表" ))
		{
			pDoc->pRightView->DisplayContent(1); 
		}

		if( nodeSelected == _T("利润表" ))
		{
			pDoc->pRightView->DisplayContent(2); 
		}

		if( nodeSelected == _T("现金流量表" ))
		{
			pDoc->pRightView->DisplayContent(3); 
		}
		if( nodeSelected == _T("自由现金流" ))
		{
			pDoc->pRightView->DisplayFinancialAnalysis(1); 
		}

	}
}
